import { h } from 'vue';
import { FormSchema } from '/@/components/Form';
import { CodeEditor } from '/@/components/CodeEditor';
enum storageType {
  mqtt = 'mqtt',
  modbus = 'modbus',
  odbc = 'odbc',
  opcda = 'opcda',
}
export const schemas: FormSchema[] = [
  {
    field: 'id',
    component: 'Input',
    label: 'ID',
    show: false,
  },
  {
    field: 'name',
    component: 'Input',
    label: '配置名称',
    componentProps: {
      placeholder: '请输入配置名称',
    },
    required: true,
  },
  {
    field: 'type',
    component: 'Select',
    label: '协议类型',
    componentProps: {
      options: [
        {
          label: storageType.mqtt,
          value: storageType.mqtt,
          key: storageType.mqtt,
        },
        {
          label: storageType.modbus,
          value: storageType.modbus,
          key: storageType.modbus,
        },
        {
          label: storageType.odbc,
          value: storageType.odbc,
          key: storageType.odbc,
        },
        {
          label: storageType.opcda,
          value: storageType.opcda,
          key: storageType.opcda,
        },
      ],
    },
    defaultValue: storageType.mqtt,
  },
  {
    field: 'host',
    component: 'Input',
    label: '域名/IP',
    componentProps: {
      placeholder: '请输入服务器域名或者IP地址',
    },
    required: true,
  },
  {
    field: 'port',
    component: 'InputNumber',
    label: '端口号',
    componentProps: {
      placeholder: '请输入服务端口号',
    },
    required: true,
  },
  {
    field: 'divider-api-select',
    component: 'Divider',
    label: '高级',
  },
  {
    field: 'config',
    component: 'Input',
    label: '',
    defaultValue: '',
    rules: [{ required: true }],
    render: ({ model, field }) => {
      return h(CodeEditor, {
        value: model[field],
        onChange: (value: string) => {
          model[field] = value;
        },
      });
    },
  },
];
export const fromConfig: Props = {
  labelCol: {
    span: 8,
  },
  wrapperCol: {
    span: 10,
  },
  showActionButtonGroup: false,
  schemas: schemas,
  actionColOptions: {
    span: 24,
  },
};
